<?php
    include "include/admin_function.php";
	session_start();
	if (isset($_POST['doCancel'])) {
		header("Location: index");
		exit;
	}
	if (isset($_POST['doLogin'])) {
		if (!isset($_POST['user_id']) || !isset($_POST['password'])){
			header("Location: login?errorMsg=" . urlencode("The User ID or password do not exist"));
			exit;
		}

		$user_id = $_POST['user_id'];
		$password = $_POST['password'];

		if (isset($_POST['autoLogin'])) {
			setcookie('user_id', $user_id);
			setcookie('password', $password);
		}
		else {
			setcookie('user_id', '');
			setcookie('password', '');
		}

		if ($user_id == "chaeyeon" && $password == "123456789" || $user_id == "alpc04" && $password == "haochidian") {
			$_SESSION['admin'] = $user_id;
			header("Location: index");
			exit;
		}
		else {
			header("Location: login?errorMsg=" . urlencode("The User ID or password do not exist"));
			exit;
		}
	}
?>
